
M	EQU	Byte Ptr 0[BX]
	TITLE	'EPSPRTR.A86'
;
;       USE ASM86 TO ASSEMBLE
;       THEN GENCMD EPSPRTR 8080
;
;***********************************************************
;                                                          *
;  EPSPRTR is a menu-driven utility to set printer op-     *
;  tions for MX printers with Graftrax +.  This program    *
;  is derived from the October 1983 Microsystems article   *
;  "Write a Menu-Driven Utility to Set Printer Options"    *
;  written by Robert L. LaFara of Castle Oaks Computer     *
;  Services, Indianapolis, IN.  Assemble with MAC or ASM.  *                  
;                                                          *
;  ------------------------------------------------------  *
;                                                          *
;  Version 1.1 by David J. Raibert, December 3, 1983       *
;  XLT86 translation by Steve Leon, March 16, 1984         *
;***********************************************************
;SET EQUATES FOR CP/M BDOS FUNCTION & CALLS
CONOUT	EQU	2			;OUTPUT TO CONSOLE
BDOS	EQU	5
LST	EQU	5			;OUTPUT TO THE LST: DEVICE
CONDIR	EQU	6			;DIRECT INPUT FROM THE CONSOLE
PRTSTR	EQU	9			;OUTPUT A STRING TO THE CONSOLE
;SET EQUATES FOR CONTROL CODE   
;(NON ESCAPE SEQUENCE) OUTPUTS
LF	EQU	8AH			;LINE FEED
TOF	EQU	0CH			;FORM FEED       
CR	EQU	0DH			;CARRIAGE RETURN
SM	EQU	8FH			;COMPRESSED PRINT
DC2	EQU	92H			;TURN OFF COMPRESSED PRINT
ESC	EQU	1BH			;ESCAPE CHARACTER                  
;INITIALIZE PROGRAM & SET STACK COUNTER
	ORG	100H
	MOV	SP,(Offset STACK)	;SET STACK COUNTER
;PRINT THE MENU
MENU:	MOV	CL,PRTSTR		;PREPARE BDOS TO OUTPUT MENU STRING
	MOV	DX,(Offset MENDAT)	;POINT TO BEGINNING OF MENU STRING
	INT	224			;PRINT THE MENU STRING
;INPUT THE CHARACTER FROM THE MENU
;STORE IT, ECHO IT TO CONSOLE
CHARIN:	MOV	CL,CONDIR		;PREPARE BDOS
	MOV	DL,0FFH			; FOR DIRECT CON-
	INT	224			;  SOLE INPUT
	CMP	AL,0			;CHARACTER RECEIVED?
	JZ	CHARIN			;IF NOT, LOOP BACK AND TRY AGAIN
	MOV	Byte Ptr CHAR,AL	;SAVE IT FOR LATER    
	MOV	CL,CONOUT		;ECHO 
	MOV	DL,AL			; IT TO
	INT	224			;  CONSOLE
;TEST FOR MENU OPTION SELECTED & JUMP TO ES-
;CAPE OR CONTROL CODE. OTHER CHARACTERS CAN
;BE USED IF < + ^ > OR @ ARE NOT AVAILABLE
	MOV	AL,Byte Ptr CHAR	;GET OPTION CHARACTER STORED AT CHAR:
	CMP	AL,'3'			;3 LINES PER INCH
	JNZ	L_1	
	JMP	V3
L_1:
	CMP	AL,'4'			;4 LINES PER INCH
	JNZ	L_2	
	JMP	V4
L_2:
	CMP	AL,'6'			;6 LINES PER INCH
	JNZ	L_3	
	JMP	V6
L_3:
	CMP	AL,'8'			;8 LINES PER INCH
	JNZ	L_4	
	JMP	V8
L_4:
	CMP	AL,'>'			;CANCEL COMPRESSED
	JNZ	L_5	
	JMP	CANCEL
L_5:
	CMP	AL,'<'			;CANCEL DOUBLE WIDTH
	JNZ	L_6	
	JMP	VV
L_6:
	CMP	AL,'^'			;CANCEL UNDERLINE
	JNZ	L_7	
	JMP	VM
L_7:
	CMP	AL,'@'			;RESET TO POWER UP INCL TOF
	JNZ	L_8	
	JMP	V@
L_8:
	CMP	AL,'+'			;CANCEL UNIDIRECTIONAL
	JNZ	L_9	
	JMP	VB
L_9:
	AND	AL,5FH			;DISCARD LOWER CASE BIT
	CMP	AL,'F'			;FORM FEED
	JNZ	L_10	
	JMP	FMFD
L_10:
	CMP	AL,'K'			;SKIP OVER PERF
	JNZ	L_11	
	JMP	VK
L_11:
	CMP	AL,'L'			;LINE FEED
	JNZ	L_12	
	JMP	LINEF
L_12:
	CMP	AL,'C'			;COMPRESSED PRINT 
	JNZ	L_13	
	JMP	CPRD
L_13:
	CMP	AL,'W'			;DOUBLE WIDTH
	JNZ	L_14	
	JMP	VW
L_14:
;DO NOT IMPLEMENT ITALICS OR SUBSCRIPT IF
; GRAFTRAX+ IS NOT INSTALLED IN THE PRINTER
	CMP	AL,'I'			;ITALICS
	JZ	VI
	CMP	AL,'J'			;CANCEL ITALICS
	JZ	VJ
	CMP	AL,'S'			;SUBSCRIPT 
	JZ	VS
	CMP	AL,'R'			;CANCEL SUBSCRIPT
	JZ	VR
	CMP	AL,'D'			;DOUBLESTRIKE
	JNZ	L_15	
	JMP	VD
L_15:
	CMP	AL,'H'			;CANCEL DOUBLESTRIKE & SUBSCRIPT
	JNZ	L_16	
	JMP	VH
L_16:
	CMP	AL,'E'			;EMPHASIZED
	JNZ	L_17	
	JMP	VE
L_17:
	CMP	AL,'Z'			;CANCEL EMPHASIZED
	JNZ	L_18	
	JMP	VZ
L_18:
	CMP	AL,'U'			;UNDERLINE
	JNZ	L_19	
	JMP	VU
L_19:
	CMP	AL,'V'			;UNIDIRECTIONAL
	JNZ	L_20	
	JMP	VA
L_20:
	CMP	AL,'Q'			;QUIT
	JNZ	L_21	
	JMP	QUIT
L_21:
	CMP	AL,'T'			;TEST
	JNZ	L_22	
	JMP	TES
L_22:
;PRINT ERROR MESSAGE
	MOV	CL,PRTSTR		;PREPARE BDOS TO OUTPUT THE ERROR
;MESSAGE STRING
	MOV	DX,(Offset ERRMSG)	;POINT TO ERROR MESSAGE
	INT	224			;PRINT IT AND
	JMP	MENU			; GO BACK TO MENU
;STORE ESCAPE CODES FOR PROCESSING AT 
;LABEL VERT:, JUMP TO SET UP ESCAPE STRING.
;NOTE THAT SINCE ESCAPE CODES ARE VARIABLE
;IN LENGTH, E. G. [ESC 'T'][ESC 'A'18],
;SINGLE ESCAPE CODES ARE PADDED WITH A '$'.
V3:	MOV	AL,'A'			;ESC 'A' 24 (/72nds)
	MOV	CH,24			;3 LINES PER INCH
	JMP	VERT
V4:	MOV	AL,'A'			;ESC 'A' 18 (/72nds)
	MOV	CH,18			;4 LINES PER INCH
	JMPS	VERT
V6:	MOV	AL,'2'			;ESC '2' 
	MOV	CH,'$'			;RESET TO 6 LINES PER INCH
	JMPS	VERT
V8:	MOV	AL,'0'			;ESC 'A' 0
	MOV	CH,'$'			;SET FOR 8 LINES PER INCH
	JMPS	VERT
VK:	MOV	AL,'N'			;ESC 'N' 6
	MOV	CH,06			;SET SKIP OVER PERF - 6 LINES
	JMPS	VERT
VI:	MOV	AL,'4'			;ESC '4'
	MOV	CH,'$'			;ITALICS
	JMPS	VERT
VJ:	MOV	AL,'5'			;ESC '5'
	MOV	CH,'$'			;CANCEL ITALICS
	JMPS	VERT
VS:	MOV	AL,'S'			;ESC 'S' 1
	MOV	CH,01			;SUBSCRIPT
	JMPS	VERT
VR:	MOV	AL,'T'			;ESC 'T'
	MOV	CH,'$'			;CANCEL SUBSCRIPT & UNIDIRECTIONAL
	JMPS	VERT
VW:	MOV	AL,'W'			;ESC 'W' 1
	MOV	CH,01			;DOUBLE WIDTH
	JMPS	VERT
VV:	MOV	AL,'W'			;ESC 'W' 0
	MOV	CH,00			;CANCEL DOUBLE WIDTH
	JMPS	VERT
VD:	MOV	AL,'G'			;ESC 'G'
	MOV	CH,'$'			;DOUBLESTRIKE
	JMPS	VERT
VH:	MOV	AL,'H'			;ESC 'H'
	MOV	CH,'$'			;CANCEL DOUBLESTRIKE & SUBSCRIPT
	JMPS	VERT
VE:	MOV	AL,'E'			;ESC 'E'
	MOV	CH,'$'			;EMPHASIZED
	JMPS	VERT
VZ:	MOV	AL,'F'			;ESC 'F'
	MOV	CH,'$'			;CANCEL EMPHASIZED
	JMPS	VERT
VU:	MOV	AL,'-'			;UNDERLINE
	MOV	CH,01
	JMPS	VERT
VM:	MOV	AL,'-'			;CANCEL UNDERLINE
	MOV	CH,00
	JMPS	VERT
VA:	MOV	AL,'U'			;UNIDIRECTIONAL
	MOV	CH,01
	JMPS	VERT
VB:	MOV	AL,'U'			;CANCEL UNIDIRECTIONAL
	MOV	CH,00
V@:	MOV	AL,'@'			;ESC '@'
	MOV	CH,'$'			;RESET ALL
	JMPS	VERT
;STORE ESCAPE SEQUENCE CODE CHARACTERS AT
;LABEL VSTR: FOR LATER OUTPUT THRU TEST1
VERT:	MOV	Byte Ptr VSTR+1,AL	;STORE 1st ESCAPE CHARACTER
;ESC (1BH) IS PROVIDED AT VSTR + 0
	MOV	AL,CH			;STORE 2nd CHARACTER OR THE
	MOV	Byte Ptr VSTR+2,AL	; PADDING '$' TERMINATOR     
	MOV	AL,'$'			;HERE IS THE OTHER '$' YOU MAY NEED 
	MOV	Byte Ptr VSTR+3,AL	; TERMINATE THE ESCAPE STRING 
	MOV	BX,(Offset VSTR)	;SET PC TO ESCAPE SEQUENCE STRING
	JMPS	TES1			;TEST FOR CHARACTERS & TERMINATOR
;SET  UP CONTROL CODES FOR OUTPUT
LINEF:	MOV	DL,LF			;LINE FEED
	JMPS	OUTPUT
FMFD:	MOV	DL,TOF			;FORM FEED
	JMPS	OUTPUT
CPRD:	MOV	DL,SM			;COMPRESSED
	JMPS	OUTPUT
CANCEL:	MOV	DL,DC2			;CANCEL COMPRESSED
	JMPS	OUTPUT
;OUTPUT CONTROL CODES TO PRINTER
OUTPUT:	MOV	CL,LST			;PREPARE BDOS TO OUTPUT TO LST:
	INT	224			; MOVE CHARACTER OUT TO PRINTER
	MOV	DL,CR			;DUMP THE PRINTER
	INT	224			; BUFFER (EMPTY IT WITH <CR>)
	JMP	MENU			;GO BACK TO THE MENU FOR ANOTHER
TES:	MOV	BX,(Offset TSTR)	;POINT TO THE BEGINNING OF THE   
;PRINTER TEST STRING
;THE ESCAPE CODES ARE PROCESSED HERE
TES1:	MOV	Word Ptr INDEX,BX	;STORE THE V-STRING ADDRESS INTO STORAGE
	MOV	DL,M			;PUT CHARACTER TO PRINT INTO E FOR OUTPUT
	MOV	AL,DL			;MOVE CHAR INTO REG 'A' TO LOOK FOR '$'
	CMP	AL,'$'			;IS IT STRING TERMINATOR '$'?
	JNZ	L_23	
	JMP	MENU			;IF SO, END TEST AND GOTO MENU
L_23:
	MOV	CL,LST			;PRINT
	INT	224			; CHARACTER
	MOV	BX,Word Ptr INDEX	;GO BACK TO STORAGE FOR STRING ADDRESS
	INC	BX			;INCREMENT PC TO NEXT CHARACTER
	JMPS	TES1			;PRINT IT
QUIT:	MOV	CL,0			;BACK TO
	INT	224			; OPERATING SYSTEM
;SET UP MENU TABLE AND STRING OUTPUT DATA
MENDAT	DB	CR,LF,'PRINTER OPTIONS MENU',CR,LF,LF
	DB	' 3 = THREE (3) LINES PER INCH     4 = FOUR (4) LINES',CR,LF
	DB	' 8 = EIGHT (8) LINES PER INCH     6 = RESET LINES',CR,LF,LF
	DB	' F = FORM FEED                    L = LINE FEED',CR,LF
	DB	' K = SKIP (SIX) OVER PERF',CR,LF
	DB	'                                  TO CANCEL OPTION',CR,LF
	DB	' C = COMPRESSED PRINT-17 CPI ##          >',CR,LF
	DB	' W = DOUBLE WIDTH-5 CPI (+C=8.5)         <',CR,LF
	DB	' I = ITALICS                             J',CR,LF
	DB	' S = FINE PRINT##                        R & H',CR,LF
	DB	' D = DOUBLESTRIKE                        H',CR,LF
	DB	' E = EMPHASIZED**                        Z',CR,LF
	DB	' U = UNDERLINE                           ^',CR,LF
	DB	' V = UNIDIRECTIONAL L ->R                +',CR,LF
	DB	' @ = RESET TO POWER-UP INCL TOF',CR,LF
	DB	'** > DO NOT USE WITH "C" OR "S" SEE ## ABOVE',CR,LF,LF
	DB	' T = TEST PRINTER                 Q = QUIT',CR,LF,LF
	DB	'ENTER OPTION  ','$'
ERRMSG	DB	CR,LF,'NO SUCH OPTION - TRY AGAIN!'
	DB	CR,LF,'$'
VSTR	DB	ESC			;PROVIDE THE 1B HEX CHARACTER HERE
	RS	3			;RESERVE SPACE FOR THE NEXT 2 OR 3
TSTR	DB	CR,LF,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',CR,LF
	DB	'abcdefghijklmnopqrstuvwxyz',CR,LF
	DB	'1234567890-=`!@#%^&*()_+~',CR,LF
	DB	'[]\|/;:''"{},.?<>',CR,LF,'$'
;RESERVE MEMORY FOR DATA AND STACK	
CHAR	RS	1			;RESERVE MEMORY FOR INPUT 
;OF THE OPTION CHARACTER 
INDEX	RS	2			;RESERVE MEMORY FOR "VSTR"     
;ADRESS WHEN STORED AT TES1
	RS	32			;DEFINE STACK - 16 LEVEL
STACK:					;TOP OF STACK
	END
